package proto_wearebatman;


public class Inverter extends Gate implements IhasInput, IhasOutput {

    private Input input;
    private Output output;
    private Wire wireInput;
    private Wire wireOutput;
    private String name;

    public Inverter(String name) {
        super(name,1,1);
        this.input = new Input();
        this.output = new Output();
        this.name = name;


        // Proto Output
        Main.println("Inverter created: " + this.name);
    }

    @Override
    public void setInputData(int pin, int data) {
        input.setData(data);
    }

    @Override
    public int getInputData(int pin) {
        return input.getData();
    }

    @Override
    public void connectWireOutput(int pin, Wire wire) {
        this.wireOutput = wire;
    }

    @Override
    public void connectWireInput(int pin, Wire wire) {
        this.wireInput = wire;
    }

    public void operate() {
        this.output.setData(this.input.getData()==1?0:1);

        //Main.println(this.name + ".operate() | Data = "+this.output.getData());

        this.wireOutput.operate();
    }

    @Override
    public int getOutputData(int pin) {
        return output.getData();
    }

    @Override
    public void setOutputData(int pin, int data) {
        this.output.setData(data);
    }


    public void resetCounter() {

    }

    public String getFinalState() {
        return Integer.toString(this.output.getData());
    }

}
